﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartCity.ProcessEngine.API.Write.Application.CommandHandlers.FormNodes;
using SmartCity.ProcessEngine.API.Write.Application.Commands.FormDetails;
using SmartCity.ProcessEngine.API.Write.Application.Commands.FormNodes;
using SmartCity.ProcessEngine.API.Write.Application.Commands.Forms;
using SmartCity.ProcessEngine.API.Write.Application.Commands.FormType;
using SmartCity.ProcessEngine.API.Write.Application.Commands.Settings;
using SmartCity.ProcessEngine.Errorcode;

namespace SmartCity.ProcessEngine.API.Write.Controllers
{
    /// <summary>
    /// API 控制器-流程引擎-写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManagementController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ManagementController> logger;

        public ManagementController(IMediator mediator,ILogger<ManagementController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 新增表单分类
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddFormType(FormTypeAddCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 删除表单分类
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回删除任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteFormType(FormTypeDeleteCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改表单分类
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回修改任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateFormType(FormTypeUpdateCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 批量添加表单明细
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回受影响的行数任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddFormDetails(FormDetailCreateCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 删除表单
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>请求</returns>
        [HttpPost]
        public async Task<ApiResult<int>> FormDelete(FormDeleteCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改表单
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回表单任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> FormUpdate(FormUpdateCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 新增节点
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回新增节点任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddNode(AddNodeCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 删除节点
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回删除节点任务</returns>
        [HttpPost]
        public async Task<IActionResult> DeleteNode(int Id)
        {
            DeleteNodeCommand request = new DeleteNodeCommand
            {
                NodeId = Id
            };
            var res = await mediator.Send(request);
            return Ok(res);
        }
        /// <summary>
        /// 修改节点
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回修改结果</returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateNode(UpdateNodeCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 新增流程设置
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回新增流程设置</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddSetting(SettingCreateCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
